<?php
if (!defined('THINK_PATH')) exit();
class PublicAction extends Action
{
    public function header(){ //头部信息
    	$mod = $this->select_mod();
    	foreach ($mod as $v){
    		$mainModlist .= ','.$v['mod'];
    	}
    	$basicinfo = selectModel::getWebBasicInfo(); //网站基本信息
    	if($basicinfo['b_state'] == 1 && !$this->checkUserLogin()){
    		redirect('/www/Public/webclose'.C('HTML_FILE_SUFFIX'));
    		exit;
    	}
    	$formUrl = __APP__.'?s=msgboard/addmsg';
    	$this->poster();
    	$this->assign('formUrl',$formUrl); //表单提交路径 公用
    	$this->assign('mainModlist',trim($mainModlist,','));
    	$this->assign('headermodule',$mod);
    	$this->assign('basicinfo',$basicinfo);
    }
    
    public function foot(){  //脚部信息
    	$mod = $this->select_footmod();
    	$links = $this->getLinksInfo();
    	$linksWay = 'discuz';
    	$this->assign('footmodule',$mod);
    	$this->assign('linksWay',$linksWay);
    	$this->assign('links',$links);
    }
    public function mainweb(){ //主引导程序
    	$this->header();
    	$this->foot();
    	$this->display();
    }
    public function recomment(){ //推荐产品
    	$recomments = selectModel::getRecomments();
    	shuffle($recomments);
    	$this->assign('recomment',$recomments);
    }
    public function poster(){ //站内广告
    	$posters = selectModel::getPosters();
    	$this->assign('poster',$posters);
    }
    
    public function webclose(){
    	$basicinfo = selectModel::getWebBasicInfo(); //网站基本信息
    	$this->assign('closeinfo',$basicinfo['b_closeinfo']);
    	$this->assign('basicinfo',$basicinfo);
    	$this->display();
    }
    public function select_footmod(){
    	return selectModel::getFootMod();
    }
    public function select_mod(){
    	return selectModel::getMainMod();
    }
    public function select_modSon(){
    	return selectModel::getModSon();
    }
    public function getLinksInfo(){
    	return selectModel::getAllLinks();
    }
	public function checkUserLogin(){
		$username = isset($_SESSION['username'])&&!empty($_SESSION['username'])?$_SESSION['username']:null;
		if(!empty($username)){
			return $username;
		}
		$username = isset($_COOKIE['username'])&&!empty($_COOKIE['username'])?$_COOKIE['username']:null;
		if(!empty($username)){
			return $username;
		}
		return false;
	}
}